//
//  TaskCenterTableViewCell.m
//  qdSubway
//
//  Created by andi911 on 2019/5/30.
//  Copyright © 2019 andi911. All rights reserved.
//

#import "TaskCenterTableViewCell.h"
@interface TaskCenterTableViewCell()
//
@property (nonatomic,strong) UIButton *righBtn;

@end

@implementation TaskCenterTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

+ (instancetype)cellWithTableView:(UITableView *)tableview{
    static NSString *cellId = @"TaskCenterTableViewCell";
    TaskCenterTableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[TaskCenterTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupview];
    }
    return self;
}

- (void)setupview{
    self.contentView.backgroundColor = [UIColor whiteColor];
    UILabel *titlteLab = [[UILabel alloc]init];
    titlteLab.width = Screen_W - 40;
    titlteLab.text = @"任务标题任务标题任务标题任务标题任务标题任务标题任务标题";
    
    titlteLab.font = [UIFont boldSystemFontOfSize:18];
    if ([titlteLab.text cly_stringHeightWithFont:titlteLab.font  width:titlteLab.width]>25) {
        titlteLab.numberOfLines = 2;
        titlteLab.height = [titlteLab.text cly_stringHeightWithFont:titlteLab.font width:titlteLab.width];
    }
    
    titlteLab.center = CGPointMake(20+titlteLab.width/2, 25+titlteLab.height/2);
    [self.contentView addSubview:titlteLab];
    
    UIImageView *leftImage = [[UIImageView alloc]initWithImage:CLYImage(@"left_panddIma")];
    leftImage.center = CGPointMake(leftImage.width/2, titlteLab.centerY);
    [self.contentView addSubview:leftImage];
    
    UILabel *contentLab = [[UILabel alloc]init];
    contentLab.width = Screen_W - 40;
    contentLab.text = @"任务标题任务标题任务标题任务标题任务标题任务标题任务标题任务标题任务标题任务标题任务标题任务标题任务标题任务标";
    if ([contentLab.text cly_stringHeightWithFont:CLYFont(16) width:contentLab.width]>20) {
        contentLab.numberOfLines = 2;
        contentLab.height = [contentLab.text cly_stringHeightWithFont:CLYFont(16) width:contentLab.width];
    }
    contentLab.font = CLYFont(16);
    contentLab.textColor = [UIColor lightGrayColor];
    contentLab.center = CGPointMake(20+contentLab.width/2, titlteLab.bottom+5+contentLab.height/2);
    [self.contentView addSubview:contentLab];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(20, contentLab.bottom+12, Screen_W-40, 0.5)];
    line.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:line];
    
    UILabel *peopleLa = [[UILabel alloc]init];
    peopleLa.font = CLYFont(14);
    peopleLa.text = @"领取人数：10/100";
    peopleLa.textColor = [UIColor grayColor];
    peopleLa.width = 120;
    peopleLa.height = 16;
    peopleLa.center = CGPointMake(contentLab.left+peopleLa.width/2, line.bottom+12+peopleLa.height/2);
    //    peopleLa.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:peopleLa];
    
    UILabel *integralLa = [[UILabel alloc]init];
    integralLa.font = CLYFont(14);
    integralLa.text = @"获取积分:10";
    integralLa.textColor = [UIColor grayColor];
    integralLa.width = 100;
    integralLa.height = 16;
    if (Screen_W<375){
        integralLa.center = CGPointMake(peopleLa.right+5+integralLa.width/2, peopleLa.centerY);
    }else{
        integralLa.center = CGPointMake(peopleLa.right+30+integralLa.width/2, peopleLa.centerY);
    }
    [self.contentView addSubview:integralLa];
    
    UILabel *taskTimeLa = [[UILabel alloc]init];
    taskTimeLa.font = CLYFont(14);
    taskTimeLa.text = @"任务时间:2017-12-12至2018-12-12";
    taskTimeLa.textColor = [UIColor grayColor];
    if (Screen_W<375) {
        taskTimeLa.width = Screen_W-40-65;
        taskTimeLa.font = CLYFont(13);
    }else{
        taskTimeLa.width = Screen_W-40-80-10;
    }
    taskTimeLa.height = 16;
    taskTimeLa.center = CGPointMake(contentLab.left+taskTimeLa.width/2, integralLa.bottom+12+taskTimeLa.height/2);
    [self.contentView addSubview:taskTimeLa];
    
    UIButton *rightBtn = [[UIButton alloc]init];
    rightBtn.width = 80;
    rightBtn.height = 40;
    rightBtn.layer.cornerRadius = 20;
    rightBtn.layer.masksToBounds = YES;
    rightBtn.backgroundColor = RGBACOLOR(37, 184, 66);
    rightBtn.titleLabel.font = CLYFont(16);
    NSString *str2 = self.status>0? @"填写反馈":@"领取";
    [rightBtn setTitle:str2 forState:0];
    [rightBtn addTarget:self action:@selector(tapBtn) forControlEvents:1<<6];
    if(Screen_W<375){
        rightBtn.width = 60;
        rightBtn.height = 30;
        rightBtn.layer.cornerRadius = 15;
        rightBtn.titleLabel.font = CLYFont(14);
    }
    
    rightBtn.center = CGPointMake(Screen_W-20-rightBtn.width/2, line.bottom+15+rightBtn.height/2);
    [self.contentView addSubview:rightBtn];
    self.righBtn = rightBtn;
    
    UIView *bottomView = [[UIView alloc]init];
    bottomView.width = Screen_W;
    bottomView.height = 8;
    bottomView.backgroundColor = RGB(247);
    bottomView.center = CGPointMake(Screen_W/2, taskTimeLa.bottom+20+bottomView.height/2);
    [self.contentView addSubview:bottomView];
    
}

- (void)setStatus:(int)status{
    _status = status;
    NSString *str2 = self.status>0? @"填写反馈":@"领取";
    [_righBtn setTitle:str2 forState:0];
}


#pragma mark ----- tapBtn ----
- (void)tapBtn{
    if ([self.delegate respondsToSelector:@selector(tapCellBtn)]) {
        [self.delegate tapCellBtn];
    }
    
}
@end
